<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>
  	<script src="resources/js/jquery.js"></script>
	<script src="resources/js/bootstrap.min.js"></script>
	<link rel="stylesheet" type="text/css" href="resources/css/datepicker.css" />
	<script src="resources/js/datepicker.js"></script>
	<script type="text/javascript">
		$(function() {
			$("input[name='gameDate']").datepicker({
			    noDefault: true, // set this to true if you don't want the current date inserted if the value-attribute is empty
			    format: 'yyyy-mm-dd hh:ii',
			    weekStart: 0,
			    days: ["일","월","화","수","목","금","토"],
			    months: ["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"]
			});
			
			if ($("select[name='gameStatus']").find("option:selected").val() != 2) {
				$("#scoreBox").hide();
			}
			
			$("select[name='gameStatus']").change(function() {
				var status = $(this).find("option:selected").val();
				if (status == 2){
					$("#scoreBox").show();
				} else {
					$("#scoreBox").hide();
				}
			});
			
			$("#type1").hide();
			$("#type2").hide();
			$("#type3").hide();
			$("#type4").hide();
			$("#type5").hide();
		});
	</script>
	<style>
  		.addon {
  			background-color: #ffffff;
  			border: 0px;
  		}
  	</style>
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h2>경기수정</h2>
		</div>

		<form id="editGame" class="form-horizontal" role="form" method="post" action="editGameOk">
			<fieldset>
			
				<input type="hidden" name="idGame" value="${item.idGame}" />
				<input type="hidden" name="page" value="${page}" />
				<input type="hidden" name="where" value="${where}" />
			
				<div class="form-group">
					<label for="isDisplay" class="col-md-2 control-label">전시여부</label>
					<div class="col-md-10">
						<label class="radio-inline">
							<input type="radio" name="isDisplay" value="1" <c:if test="${item.isDisplay == 1}">checked</c:if>> 활성
						</label>
						<label class="radio-inline">
							<input type="radio" name="isDisplay" value="0" <c:if test="${item.isDisplay == 0}">checked</c:if>> 비활성
						</label>
					</div>
				</div>
				
				<div class="form-group">
					<label for="gameStatus" class="col-md-2 control-label">경기상태</label>
					<div class="col-md-10">
					
						<div class="row">
							<div class="col-md-6">
								<select name="gameStatus" class="form-control">
									<option>- 선택하세요 -</option>
									<option value="1" <c:if test="${item.gameStatus == 1}">selected</c:if>>판매중</option>
									<option value="2" <c:if test="${item.gameStatus == 2}">selected</c:if>>경기종료</option>
									<option value="3" <c:if test="${item.gameStatus == 3}">selected</c:if>>경기취소</option>
								</select>
							</div>
							<div id="scoreBox" class="col-md-6 input-group input-group-sm">
								<input type="number" class="form-control" name="homeScore" 
									placeholder="홈팀점수" <c:if test="${item.homeScore != -1}">value="${item.homeScore}"</c:if>/>
								<span class="input-group-addon addon">:</span>
								<input type="number" class="form-control" name="awayScore" 
									placeholder="원정팀점수" <c:if test="${item.awayScore != -1}">value="${item.awayScore}"</c:if>/>
							</div>
						</div>
						
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-md-2 control-label">경기번호</label>
					<div class="col-md-10">
						<p class="form-control-static">${item.idGame}</p>
					</div>
				</div>
			
				<div class="form-group">
					<label for="idHomeTeam" class="col-md-2 control-label">경기리그</label>
					<div class="col-md-10">
						<div class="row">
							<div class="col-md-2">
								<select class="form-control" name="idSport">
									<option value="default">- 종목 -</option>
									<c:forEach items="${sportList}" var="sportList">
										<option value="${sportList.idSport}" <c:if test="${sportList.idSport == item.idSport}">selected</c:if>>${sportList.sportName}</option>
									</c:forEach>
								</select>
							</div>
							<div class="col-md-4">
								<select class="form-control" name="idLeague">
									<option value="default">- 종목을 먼저 선택하여 주세요 -</option>
								</select>
							</div>
							<div class="col-md-6">
								<input type="text" class="form-control" name="leagueInfo" placeholder="리그정보를 입력하세요" value="${item.leagueInfo}" />
							</div>
						</div>
					</div>
				</div>
			
				<div class="form-group">
					<label for="idHomeTeam" class="col-md-2 control-label">홈팀</label>
					<div class="col-md-10">
						<div class="row">
							<div class="col-md-2">
								<select class="form-control" name="homeSport">
									<option value="default">- 종목 -</option>
									<c:forEach items="${sportList}" var="sportList">
										<option value="${sportList.idSport}" <c:if test="${sportList.idSport == item.idHomeSport}">selected</c:if>>${sportList.sportName}</option>
									</c:forEach>
								</select>
							</div>
							<div class="col-md-4">
								<select class="form-control" name="homeLeague">
									<option value="default">- 종목을 먼저 선택하여 주세요 -</option>
								</select>
							</div>
							<div class="col-md-6">
								<select class="form-control" name="idHomeTeam">
									<option value="default">- 리그를 먼저 선택하여 주세요 -</option>
								</select>
							</div>
						</div>
					</div>
				</div>
				
				<div class="form-group">
					<label for="idAwayTeam" class="col-md-2 control-label">원정팀</label>
					<div class="col-md-10">
						<div class="row">
							<div class="col-md-2">
								<select class="form-control" name="awaySport">
									<option value="default">- 종목 -</option>
									<c:forEach items="${sportList}" var="sportList">
										<option value="${sportList.idSport}" <c:if test="${sportList.idSport == item.idAwaySport}">selected</c:if>>${sportList.sportName}</option>
									</c:forEach>
								</select>
							</div>
							<div class="col-md-4">
								<select class="form-control" name="awayLeague">
									<option value="default">- 종목을 먼저 선택하여 주세요 -</option>
								</select>
							</div>
							<div class="col-md-6">
								<select class="form-control" name="idAwayTeam">
									<option value="default">- 리그를 먼저 선택하여 주세요 -</option>
								</select>
							</div>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label for="gameDate" class="col-md-2 control-label">경기시간</label>
					<div class="col-md-10">
						<fmt:parseDate value="${item.gameDate.substring(0, 12)}" var="dateFmt" pattern="yyyyMMddHHmm"/>
						<input type="text" class="form-control" name="gameDate" placeholder="yyyy-mm-dd hh:mm" 
							value="<fmt:formatDate value='${dateFmt}' pattern='yyyy-MM-dd HH:mm'/>"/>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-md-2 control-label">경기종류</label>
					<div class="col-md-10">
						<label class="checkbox-inline">
							<input type="checkbox" id="gameType1" name="gameType" value="1" <c:if test="${gameType1.gameType == 1}">checked</c:if>>승무패
						</label>
						<label class="checkbox-inline">
							<input type="checkbox" id="gameType2" name="gameType" value="2" <c:if test="${gameType2.gameType == 2}">checked</c:if>>승패
						</label>
						<label class="checkbox-inline">
							<input type="checkbox" id="gameType3" name="gameType" value="3" <c:if test="${gameType3.gameType == 3}">checked</c:if>>핸디승무패
						</label>
						<label class="checkbox-inline">
							<input type="checkbox" id="gameType4" name="gameType" value="4" <c:if test="${gameType4.gameType == 4}">checked</c:if>>핸디승패
						</label>
						<label class="checkbox-inline">
							<input type="checkbox" id="gameType5" name="gameType" value="5" <c:if test="${gameType5.gameType == 5}">checked</c:if>>언오버
						</label>
						<label class="checkbox-inline">
							<input type="checkbox" id="gameType6" name="gameType" value="6" <c:if test="${gameType6.gameType == 6}">checked</c:if>>기타
						</label>
					</div>
				</div>
				
				<div class="form-group" id="type1">
					<label class="col-md-2 control-label">승무패</label>
					<div class="col-md-10">
						<div class="form-group">
							<div class="col-md-4 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;승&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="homeRate1" step="0.01" value="${gameType1.homeRate}" />
							</div>
							<div class="col-md-4 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;무&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="tieRate1" step="0.01" value="${gameType1.tieRate}" />
							</div>
							<div class="col-md-4 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;패&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="awayRate1" step="0.01" value="${gameType1.awayRate}" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="form-group" id="type2">
					<label class="col-md-2 control-label">승패</label>
					<div class="col-md-10">
						<div class="form-group">
							<div class="col-md-6 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;승&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="homeRate2" step="0.01" value="${gameType2.homeRate}" />
							</div>
							<div class="col-md-6 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;패&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="awayRate2" step="0.01" value="${gameType2.awayRate}" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="form-group" id="type3">
					<label class="col-md-2 control-label">핸디승무패</label>
					<div class="col-md-10">
						<div class="form-group">
							<div class="col-md-3 input-group">
								<span class="input-group-addon">핸디캡</span>
								<input type="number" class="form-control" name="handiRate3" step="0.1" value="${gameType3.rate}" />
							</div>
							<div class="col-md-3 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;승&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="homeRate3" step="0.01" value="${gameType3.homeRate}" />
							</div>
							<div class="col-md-3 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;무&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="tieRate3" step="0.01" value="${gameType3.tieRate}" />
							</div>
							<div class="col-md-3 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;패&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="awayRate3" step="0.01" value="${gameType3.awayRate}" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="form-group" id="type4">
					<label class="col-md-2 control-label">핸디승패</label>
					<div class="col-md-10">
						<div class="form-group">
							<div class="col-md-4 input-group">
								<span class="input-group-addon">핸디캡</span>
								<input type="number" class="form-control" name="handiRate4" step="0.1" value="${gameType4.rate}" />
							</div>
							<div class="col-md-4 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;승&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="homeRate4" step="0.01" value="${gameType4.homeRate}" />
							</div>
							<div class="col-md-4 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;패&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="awayRate4" step="0.01" value="${gameType4.awayRate}" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="form-group" id="type5">
					<label class="col-md-2 control-label">언오버</label>
					<div class="col-md-10">
						<div class="form-group">
							<div class="col-md-4 input-group">
								<span class="input-group-addon">언오버</span>
								<input type="number" class="form-control" name="unoverRate5" step="0.1" value="${gameType5.rate}" />
							</div>
							<div class="col-md-4 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;승&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="homeRate5" step="0.01" value="${gameType5.homeRate}" />
							</div>
							<div class="col-md-4 input-group">
								<span class="input-group-addon">&nbsp;&nbsp;패&nbsp;&nbsp;</span>
								<input type="number" class="form-control" name="awayRate5" step="0.01" value="${gameType5.awayRate}" />
							</div>
						</div>
					</div>
				</div>
				
				<div class="form-group">
					<label for="gameInfo" class="col-md-2 control-label">경기추가정보</label>
					<div class="col-md-10">
						<textarea name="gameInfo" class="form-control" rows="7" placeholder="경기에 대한 추가정보를 입력하세요">${item.gameInfo}</textarea>
					</div>
				</div>
				
				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">수정하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>

					</div>
				</div>
			</fieldset>
		</form>
	</div>
	
	<script type="text/javascript">
		$(function() {
			
			if ($("select[name='idSport'] > option:selected").index() > 0) {
				$("select[name='idLeague']").empty();
				
				var sport = $("select[name='idSport']").find("option:selected").val();
				
				$.ajax({
					url: "league",
					data: "sport=" + sport,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							if (idLeague == "${item.idLeague}") {
								option.attr({'selected' : "selected"});
							}
							
							$("select[name='idLeague']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			}
			
			if ($("select[name='homeSport'] > option:selected").index() > 0) {
				$("select[name='homeLeague']").empty();
				
				var sport = $("select[name='homeSport']").find("option:selected").val();
				
				$.ajax({
					url: "league",
					data: "sport=" + sport,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							if (idLeague == "${item.idHomeLeague}") {
								option.attr({'selected' : "selected"});
							}
							
							$("select[name='homeLeague']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			}
			
			if ($("select[name='awaySport'] > option:selected").index() > 0) {
				$("select[name='awayLeague']").empty();
				
				var sport = $("select[name='awaySport']").find("option:selected").val();
				
				$.ajax({
					url: "league",
					data: "sport=" + sport,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							if (idLeague == "${item.idAwayLeague}") {
								option.attr({'selected' : "selected"});
							}
							
							$("select[name='awayLeague']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			}
			
			if ($("select[name='homeLeague'] > option:selected").index() > 0) {
				$("select[name='idHomeTeam']").empty();
				
				var league = $("select[name='homeLeague']").find("option:selected").val();
				
				$.ajax({
					url: "team",
					data: "league=" + league,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idTeam = $(this).find("idTeam").text();
							var teamName = $(this).find("teamName").text();
							
							var option = $("<option>").html(teamName);
							option.attr({'value' : idTeam});
							
							if (idTeam == "${item.idHomeTeam}") {
								option.attr({'selected' : "selected"});
							}
							
							$("select[name='idHomeTeam']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			}
			
			if ($("select[name='awayLeague'] > option:selected").index() > 0) {
				$("select[name='idAwayTeam']").empty();
				
				var league = $("select[name='awayLeague']").find("option:selected").val();
				
				$.ajax({
					url: "team",
					data: "league=" + league,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idTeam = $(this).find("idTeam").text();
							var teamName = $(this).find("teamName").text();
							
							var option = $("<option>").html(teamName);
							option.attr({'value' : idTeam});
							
							if (idTeam == "${item.idAwayTeam}") {
								option.attr({'selected' : "selected"});
							}
							
							$("select[name='idAwayTeam']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			}
			
			$("select[name='idSport']").change(function() {
				$("select[name='idLeague']").empty();
				$("select[name='homeLeague']").empty();
				$("select[name='awayLeague']").empty();
				
				var sport = $(this).find("option:selected").val();
				
				$("select[name='homeSport']").val(sport).attr("selected", "selected");
				$("select[name='awaySport']").val(sport).attr("selected", "selected");
				
				$.ajax({
					url: "league",
					data: "sport=" + sport,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							$("select[name='idLeague']").append(option);
						});
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							$("select[name='homeLeague']").append(option);
						});
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							$("select[name='awayLeague']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			});
			
			$("select[name='homeSport']").change(function() {
				$("select[name='homeLeague']").empty();
				$("select[name='idHomeTeam']").empty();
				var option1 = $("<option>").html("- 리그를 먼저 선택하여 주세요 -");
				option1.attr({'value' : 'default'});
				$("select[name='idHomeTeam']").append(option1);
				
				var sport = $(this).find("option:selected").val();
				
				$.ajax({
					url: "league",
					data: "sport=" + sport,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							$("select[name='homeLeague']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			});
			
			$("select[name='awaySport']").change(function() {
				$("select[name='awayLeague']").empty();
				$("select[name='idAwayTeam']").empty();
				var option1 = $("<option>").html("- 리그를 먼저 선택하여 주세요 -");
				option1.attr({'value' : 'default'});
				$("select[name='idAwayTeam']").append(option1);
				
				var sport = $(this).find("option:selected").val();
				
				$.ajax({
					url: "league",
					data: "sport=" + sport,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							$("select[name='awayLeague']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			});
			
			$("select[name='idLeague']").change(function() {
				$("select[name='homeLeague']").empty();
				$("select[name='awayLeague']").empty();
				
				var sport = $("select[name='idSport']").find("option:selected").val();
				
				$("select[name='homeSport']").val(sport).attr("selected", "selected");
				$("select[name='awaySport']").val(sport).attr("selected", "selected");
				
				$("select[name='idHomeTeam']").empty();
				$("select[name='idAwayTeam']").empty();
				
				var league = $(this).find("option:selected").val();
				
				$.ajax({
					url: "league",
					data: "sport=" + sport,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							if (idLeague == league) {
								option.attr({'selected' : "selected"});
							}
							
							$("select[name='homeLeague']").append(option);
						});
						$(req).find("item").each(function() {
							var idLeague = $(this).find("idLeague").text();
							var leagueName = $(this).find("leagueName").text();
							
							var option = $("<option>").html(leagueName);
							option.attr({'value' : idLeague});
							
							if (idLeague == league) {
								option.attr({'selected' : "selected"});
							}
							
							$("select[name='awayLeague']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
				
				$.ajax({
					url: "team",
					data: "league=" + league,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idTeam = $(this).find("idTeam").text();
							var teamName = $(this).find("teamName").text();
							
							var option = $("<option>").html(teamName);
							option.attr({'value' : idTeam});
							
							$("select[name='idHomeTeam']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
				
				$.ajax({
					url: "team",
					data: "league=" + league,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idTeam = $(this).find("idTeam").text();
							var teamName = $(this).find("teamName").text();
							
							var option = $("<option>").html(teamName);
							option.attr({'value' : idTeam});
							
							$("select[name='idAwayTeam']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
				
			});
			
			$("select[name='homeLeague']").change(function() {
				$("select[name='idHomeTeam']").empty();
				
				var league = $(this).find("option:selected").val();
				
				$.ajax({
					url: "team",
					data: "league=" + league,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idTeam = $(this).find("idTeam").text();
							var teamName = $(this).find("teamName").text();
							
							var option = $("<option>").html(teamName);
							option.attr({'value' : idTeam});
							
							$("select[name='idHomeTeam']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			});
			
			$("select[name='awayLeague']").change(function() {
				$("select[name='idAwayTeam']").empty();
				
				var league = $(this).find("option:selected").val();
				
				$.ajax({
					url: "team",
					data: "league=" + league,
					dataType: "xml",
					timeout: 30000,
					cache: false,
					async: false,
					success: function(req) {
						$(req).find("item").each(function() {
							var idTeam = $(this).find("idTeam").text();
							var teamName = $(this).find("teamName").text();
							
							var option = $("<option>").html(teamName);
							option.attr({'value' : idTeam});
							
							$("select[name='idAwayTeam']").append(option);
						});
					},
					error: function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			});
			
		});
	</script>
	
	<!-- 형식검사 클래스 참조 -->
	<script src="resources/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			
			if ($("input:checkbox[id='gameType1']").is(":checked")) {
				$("#type1").show();
			}
			if ($("input:checkbox[id='gameType2']").is(":checked")) {
				$("#type2").show();
			}
			if ($("input:checkbox[id='gameType3']").is(":checked")) {
				$("#type3").show();
			}
			if ($("input:checkbox[id='gameType4']").is(":checked")) {
				$("#type4").show();
			}
			if ($("input:checkbox[id='gameType5']").is(":checked")) {
				$("#type5").show();
			}
			
			$("#gameType1").click(function() {
				$("#type1").toggle();
			});
			
			$("#gameType2").click(function() {
				$("#type2").toggle();
			});
			
			$("#gameType3").click(function() {
				$("#type3").toggle();
			});
			
			$("#gameType4").click(function() {
				$("#type4").toggle();
			});
			
			$("#gameType5").click(function() {
				$("#type5").toggle();
			});
			
			$("#editGame").submit(function() {
				
				if (!$("input[name='isDisplay']").is(":checked")) {
					alert("전시여부를 선택해 주세요");
					$("input[name='isDisplay']").focus();
					return false;
				}
				
				if ($("select[name='gameStatus'] > option:selected").index() < 1) {
					alert("경기상태를 선택하세요.");
					$("select[name='gameStatus']").focus();
					return false;
				}
				
				if ($("select[name='gameStatus']").find("option:selected").val() == 2) {
					if (!$("input[name='homeScore']").val().isValue()) {
						alert("홈팀점수를 입력하세요.");
						$("input[name='homeScore']").focus();
						return false;
					}
					if (!$("input[name='awayScore']").val().isValue()) {
						alert("원정팀점수를 입력하세요.");
						$("input[name='awayScore']").focus();
						return false;
					}
				}
				
				if ($("select[name='idLeague'] > option:selected").index() < 1) {
					alert("경기리그를 선택하세요.");
					$("select[name='idLeague']").focus();
					return false;
				}
				
				if ($("select[name='idHomeTeam'] > option:selected").index() < 1) {
					alert("홈팀을 선택하세요.");
					$("select[name='idHomeTeam']").focus();
					return false;
				}
				
				if ($("select[name='idAwayTeam'] > option:selected").index() < 1) {
					alert("원정팀을 선택하세요.");
					$("select[name='idAwayTeam']").focus();
					return false;
				}
				
				if (!$("input[name='gameDate']").val().isValue()) {
					alert("경기시간을 입력하세요.");
					$("input[name='gameDate']").focus();
					return false;
				}
				
				var type1Check = $("input:checkbox[id='gameType1']").is(":checked");
				if (type1Check) {
					if (!$("input[name='homeRate1']").val().isValue()) {
						alert("승무패의 승배당을 입력하세요.");
						$("input[name='homeRate1']").focus();
						return false;
					}
					
					if (!$("input[name='homeRate1']").val().isFloat()) {
						alert("승무패의 승배당은 정수나 실수로만 입력하세요.");
						$("input[name='homeRate1']").focus();
						return false;
					}
					
					if (!$("input[name='tieRate1']").val().isValue()) {
						alert("승무패의 무배당을 입력하세요.");
						$("input[name='tieRate1']").focus();
						return false;
					}
					
					if (!$("input[name='tieRate1']").val().isFloat()) {
						alert("승무패의 무배당은 정수나 실수로만 입력하세요.");
						$("input[name='tieRate1']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate1']").val().isValue()) {
						alert("승무패의 패배당을 입력하세요.");
						$("input[name='awayRate1']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate1']").val().isFloat()) {
						alert("승무패의 패배당은 정수나 실수로만 입력하세요.");
						$("input[name='awayRate1']").focus();
						return false;
					}
				}
				
				var type2Check = $("input:checkbox[id='gameType2']").is(":checked");
				if (type2Check) {
					if (!$("input[name='homeRate2']").val().isValue()) {
						alert("승패의 승배당을 입력하세요.");
						$("input[name='homeRate2']").focus();
						return false;
					}
					
					if (!$("input[name='homeRate2']").val().isFloat()) {
						alert("승패의 승배당은 정수나 실수로만 입력하세요.");
						$("input[name='homeRate2']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate2']").val().isValue()) {
						alert("승패의 패배당을 입력하세요.");
						$("input[name='awayRate2']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate2']").val().isFloat()) {
						alert("승패의 패배당은 정수나 실수로만 입력하세요.");
						$("input[name='awayRate2']").focus();
						return false;
					}
				}
				
				var type3Check = $("input:checkbox[id='gameType3']").is(":checked");
				if (type3Check) {
					if (!$("input[name='handiRate3']").val().isValue()) {
						alert("핸디승무패의 핸디기준점을 입력하세요.");
						$("input[name='handiRate3']").focus();
						return false;
					}
					
					if (!$("input[name='handiRate3']").val().isFloat2()) {
						alert("핸디승무패의 핸디기준점은 정수나 실수로만 입력하세요.");
						$("input[name='handiRate3']").focus();
						return false;
					}
					
					if (!$("input[name='homeRate3']").val().isValue()) {
						alert("핸디승무패의 승배당을 입력하세요.");
						$("input[name='homeRate3']").focus();
						return false;
					}
					
					if (!$("input[name='homeRate3']").val().isFloat()) {
						alert("핸디승무패의 승배당은 정수나 실수로만 입력하세요.");
						$("input[name='homeRate3']").focus();
						return false;
					}
					
					if (!$("input[name='tieRate3']").val().isValue()) {
						alert("핸디승무패의 무배당을 입력하세요.");
						$("input[name='tieRate3']").focus();
						return false;
					}
					
					if (!$("input[name='tieRate3']").val().isFloat()) {
						alert("핸디승무패의 무배당은 정수나 실수로만 입력하세요.");
						$("input[name='tieRate3']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate3']").val().isValue()) {
						alert("핸디승무패의 패배당을 입력하세요.");
						$("input[name='awayRate3']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate3']").val().isFloat()) {
						alert("핸디승무패의 패배당은 정수나 실수로만 입력하세요.");
						$("input[name='awayRate3']").focus();
						return false;
					}
				}
				
				var type4Check = $("input:checkbox[id='gameType4']").is(":checked");
				if (type4Check) {
					if (!$("input[name='handiRate4']").val().isValue()) {
						alert("핸디승패의 핸디기준점을 입력하세요.");
						$("input[name='handiRate4']").focus();
						return false;
					}
					
					if (!$("input[name='handiRate4']").val().isFloat2()) {
						alert("핸디승패의 핸디기준점은 정수나 실수로만 입력하세요.");
						$("input[name='handiRate4']").focus();
						return false;
					}
					
					if (!$("input[name='homeRate4']").val().isValue()) {
						alert("핸디승패의 승배당을 입력하세요.");
						$("input[name='homeRate4']").focus();
						return false;
					}
					
					if (!$("input[name='homeRate4']").val().isFloat()) {
						alert("핸디승패의 승배당은 정수나 실수로만 입력하세요.");
						$("input[name='homeRate4']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate4']").val().isValue()) {
						alert("핸디승패의 패배당을 입력하세요.");
						$("input[name='awayRate4']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate4']").val().isFloat()) {
						alert("핸디승패의 패배당은 정수나 실수로만 입력하세요.");
						$("input[name='awayRate4']").focus();
						return false;
					}
				}
				
				var type5Check = $("input:checkbox[id='gameType5']").is(":checked");
				if (type5Check) {
					if (!$("input[name='unoverRate5']").val().isValue()) {
						alert("언오버의 핸디기준점을 입력하세요.");
						$("input[name='unoverRate5']").focus();
						return false;
					}
					
					if (!$("input[name='unoverRate5']").val().isFloat2()) {
						alert("언오버의 핸디기준점은 정수나 실수로만 입력하세요.");
						$("input[name='unoverRate5']").focus();
						return false;
					}
					
					if (!$("input[name='homeRate5']").val().isValue()) {
						alert("언오버의 승배당을 입력하세요.");
						$("input[name='homeRate5']").focus();
						return false;
					}
					
					if (!$("input[name='homeRate5']").val().isFloat()) {
						alert("언오버의 승배당은 정수나 실수로만 입력하세요.");
						$("input[name='homeRate5']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate5']").val().isValue()) {
						alert("언오버의 패배당을 입력하세요.");
						$("input[name='awayRate5']").focus();
						return false;
					}
					
					if (!$("input[name='awayRate5']").val().isFloat()) {
						alert("언오버의 패배당은 정수나 실수로만 입력하세요.");
						$("input[name='awayRate5']").focus();
						return false;
					}
				}
				
				var type6Check = $("input:checkbox[id='gameType6']").is(":checked");
				if (!type1Check && !type2Check && !type3Check && !type4Check && !type5Check && !type6Check) {
					alert("경기종류를 최소한 1개이상은 선택하여 주세요.");
					$("input:checkbox[id='gameType1']").focus();
					return false;
				}
				
				if (!confirm("정말 수정 하시겠습니까?")) {
					return false;
				}
			});
		});
	</script>
  </body>
</html>